/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package diagram.connections;

import data.PredefinedObjects;
import diagram.handles.ConnectHandle;
import diagram.handles.TriggerHandle;
import diagram.locations.Location;
import java.awt.Graphics2D;
import javax.swing.Timer;
import listeners.TimerListener;
import model.DiagramModel;

/**
 *
 * @author Jelle
 */
public class TriggerConnection extends Connection {

    private TriggerHandle handleSource;
    private TriggerHandle handleTarget;
    private PredefinedObjects objects = new PredefinedObjects();
    private DiagramModel model;

    public TriggerConnection(Location source, Location target, DiagramModel model) {
        super(source, target);
        this.model = model;
    }

    public TriggerConnection(TriggerHandle csource, TriggerHandle ctarget) {
        super(csource.getLocation(), ctarget.getLocation());
        this.handleSource = csource;
        this.handleTarget = ctarget;
    }

    @Override
    public void paint(Graphics2D g) {
        g.setStroke(objects.getDashedStroke());
        getLine().setLine(getSource().getX(), getSource().getY(), getTarget().getX(), getTarget().getY());
        g.draw(getLine());
        g.setStroke(objects.getBasicStroke());
    }

    /**
     * @return the handleSource
     */
    public TriggerHandle getHandleSource() {
        return handleSource;
    }

    /**
     * @param handleSource the handleSource to set
     */
    public void setHandleSource(TriggerHandle handleSource) {
        this.handleSource = handleSource;
    }

    /**
     * @return the handleTarget
     */
    public TriggerHandle getHandleTarget() {
        return handleTarget;
    }

    /**
     * @param handleTarget the handleTarget to set
     */
    public void setHandleTarget(TriggerHandle handleTarget) {
        this.handleTarget = handleTarget;
    }

    public void print() {
        System.out.println("source X:" + getSource().getX() + "- Y:" + getSource().getY());
        System.out.println("target X:" + getTarget().getX() + "- Y:" + getTarget().getY());
    }

    public void shrink(ConnectHandle hc){
        System.out.println("in shrink");

        int x1 = getSource().getX();
        int x2 = getSource().getY();
        int y1 = getTarget().getX();
        int y2 = getTarget().getY();
        int h = y2 - x2;
        int b = y1 - x1;
        System.out.println("b:"+b+" h:"+h);


        Timer t = new Timer(3, new TimerListener(this, b, h,hc, model));
        t.start();

    }
}
